package com.market.action;

import com.market.domain.PageBean;
import com.market.domain.Product;
import com.market.service.ProductService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class ProductAction extends ActionSupport implements ModelDriven<Product> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Product product = new Product();
	
	@Override
	public Product getModel() {
		// TODO Auto-generated method stub
		return product;
	}
	
	public ProductService productService;
	public void setProductService(ProductService productService) {
		this.productService = productService;
	}
	private int PID;
	
	public void setPID(int pID) {
		this.PID = pID+1;
	}

	//接受一个page
	private Integer currentPage=1;
	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	//通过page来查询商品
	public String findAll() {
		PageBean<Product> pageBean=productService.findByProductAll(currentPage);
		//将pageBean存入值栈
		ActionContext.getContext().getSession().put("pageBean", pageBean);
		ActionContext.getContext().getValueStack().push(pageBean);
		return INPUT;
	}
	//通过商品的id将其保存到session
	public String byIdSaveProduct() {
		Product product=productService.byidsaveProduct(PID);
		ActionContext.getContext().getSession().put("currentProduct", product);
		System.out.println(product.getPname());
		return SUCCESS;
	}
}
